package de.gdgkarlsruhe.programminfo;

import java.util.List;

import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * 
 * @author GDG Karlsruhe
 */
public class TrackListAdapter extends ArrayAdapter<Track> {
  
  private static final int VIEW_ID =  R.layout.row_track;

  private List<Track> mItems;
  private Fragment mCallingFragment;
  
  private static class ViewHolder {
    TextView title;
    TextView text;
  }
  
  
  public TrackListAdapter(Fragment callingFragment, List<Track> items) {
    super(callingFragment.getActivity(), VIEW_ID, items);
    this.mItems = items;
    this.mCallingFragment = callingFragment;
  }
  
  @Override
  public View getView(int position, View savedView, ViewGroup parent) {
    if (savedView == null) {
      LayoutInflater vi = (LayoutInflater) mCallingFragment.getActivity().getLayoutInflater();
      savedView = vi.inflate(VIEW_ID, null);
      ViewHolder holder = new ViewHolder();
      holder.title = (TextView) savedView.findViewById(R.id.rowTitle);
      holder.text = (TextView) savedView.findViewById(R.id.rowText);
      savedView.setTag(holder);
    }
    ViewHolder holder = (ViewHolder) savedView.getTag();
   
    Track item = mItems.get(position);
    if (item != null) {
      holder.title.setText(item.getTitle());
      holder.text.setText(item.getSpeaker());
    }
    
    return savedView;
  }
  
}
